package com.CMS.server.dao;

import java.util.ArrayList;
import java.util.List;

import com.CMS.server.domain.Privilege;
import com.CMS.server.domain.Rol;

public class RolDao extends BaseDao<Rol>{

	public List<Privilege> getPrivileges(long id){
		List<Privilege> p = null;
		try{
			Rol r = getEntity(id);
			p = r.getPrivileges();
		}
		catch (Exception e) {
			e.printStackTrace();
		}		
		return p;
	}
	
	
	public void updatePrivileges(long idRol,List<Long> lista){
		List<Privilege> aux = new ArrayList<Privilege>();
		PrivilegeDao pd = new PrivilegeDao();
		RolDao dao = new RolDao();
		Rol r = dao.getEntity(idRol);
		
		for(int i=0; i<lista.size(); i++){
			aux.add(pd.getEntity(lista.get(i)));
		}
		
		r.setPrivileges(aux);
		dao.updateEntity(r);
	}
}
